package com.retlife.tvshow.global

import android.app.Activity
import android.app.Application
import android.content.Context
import android.content.res.Configuration
import android.os.Bundle
import com.retlife.tvshow.global.manager.BgmManager
import org.greenrobot.eventbus.EventBus
import java.util.concurrent.Executors
import java.util.concurrent.ScheduledExecutorService
import java.util.concurrent.TimeUnit

class MyApplication : Application() {
    private  var scheduledExecutorService: ScheduledExecutorService
    private var b = false

    init {
        context = this
        scheduledExecutorService = Executors.newSingleThreadScheduledExecutor()
    }

    override fun onCreate() {
        super.onCreate()
//        val crashHandler: CrashHandler = CrashHandler.instance
        //        BgmManager.getInstance();
//        crashHandler.init(this)
        context = this
        registerActivityLifecycleCallbacks(object : ActivityLifecycleCallbacks {
            override fun onActivityCreated(
                activity: Activity,
                savedInstanceState: Bundle?,
            ) {
            }

            override fun onActivityStarted(activity: Activity) {}
            override fun onActivityResumed(activity: Activity) {}
            override fun onActivityPaused(activity: Activity) {}
            override fun onActivityStopped(activity: Activity) {}
            override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}
            override fun onActivityDestroyed(activity: Activity) {}
        })
        scheduledExecutorService.scheduleAtFixedRate({
            b = !b
            EventBus.getDefault().post(EventBusMsg(EventBusOrder.TIMER, b))
        }, 5000, 30, TimeUnit.MILLISECONDS)
        BgmManager.instance = BgmManager(this)

    }

    companion object {
        var isShowLog: Boolean = false


        var context: Context? = null

        fun get(): Context = context!!
    }
}
